import { getAction, putAction, postAction } from '@/api/manage'
import { serviceApi } from '@/api/common.js'
/**
 * 公共API接口
 */
export const api = {
  list: (departId) => serviceApi.auth + `/departs/${departId}/roles`,
  getDeptRoleList: (departId) => serviceApi.auth + `/departs/${departId}/roles/list`,
  getDeptRoleByUserId: (departId, userId) => serviceApi.auth + `/departs/${departId}/roles/users/${userId}`,
  addUserDeptRole: (departId) => serviceApi.auth + `/departs/${departId}/roles/users`,
  delete: (departId, ids) => serviceApi.auth + `/departs/${departId}/roles/${ids}`,
  deleteBatch: (departId) => serviceApi.auth + `/departs/${departId}/roles/delete-batch`,
  add: (departId) => serviceApi.auth + `/departs/${departId}/roles`,
  edit: (departId) => serviceApi.auth + `/departs/${departId}/roles`
}

/**
 * 通过用户ID查询部门角色信息
 * @param {*} params
 * @returns
 */
export const getDeptRoleByUserId = (departId, userId, params) => getAction(api.getDeptRoleByUserId(departId, userId), params)

/**
 * 添加用户部门角色信息
 * @param params
 * @returns {AxiosPromise}
 */
export const addUserDeptRole = (departId, params) => postAction(api.addUserDeptRole(departId), params)

/**
 * 获取部门角色信息
 * @param params
 * @returns {AxiosPromise}
 */
export const getDeptRoleList = (departId, params) => getAction(api.getDeptRoleList(departId), params)

/**
 * 获取部门角色
 * @param params
 * @returns {AxiosPromise}
 */
export const getDeptRole = (departId, params) => getAction(api.list(departId), params)

/**
 * 添加部门角色
 * @param params
 * @returns {AxiosPromise}
 */
export const addDeptRole = (departId, params) => postAction(api.add(departId), params)

/**
 * 编辑部门角色
 * @param params
 * @returns {AxiosPromise}
 */
export const editDeptRole = (departId, params) => putAction(api.edit(departId), params)

/**
 * 保存部门角色权限
 * @param params
 * @returns {AxiosPromise}
 */
export const saveDeptRoleAppPermission = params => postAction(serviceApi.auth + '/departs/roles/permissions', params)

/**
 * 查询部门角色应用权限
 * @param appId
 * @param params {tenantId: '', departId: ''}
 * @returns {AxiosPromise}
 */
export const queryDepartAppPermissionTree = (appId, params) => getAction(serviceApi.auth + `/departs/roles/permissions/apps/${appId}/trees`, params)

/**
 * 通过角色ID查询部门权限
 * @param params
 * @returns {AxiosPromise}
 */
export const queryDepartPermissionByRoleId = (appId, params) => getAction(serviceApi.auth + `/departs/roles/permissions/apps/${appId}`, params)

/**
 * 我的部门 获取部门角色应用权限
 * @param departId
 * @param roleId
 * @param params { tenantId: '',departId: '',roleId: '' }
 * @returns {AxiosPromise}
 */
export const queryAppTreeByDepartRole = (params) => getAction(serviceApi.auth + '/departs/roles/permissions/apps', params)

/**
 * 获取部门角色权限数据规则
 * @param {*} params
 * @returns
 */
export const queryDepartRolePermissionDataRule = (params) => getAction(serviceApi.auth + '/departs/roles/permissions/data-rules', params);

/**
 * 保存部门角色权限数据规则
 * @param {*} params
 * @returns
 */
export const saveDepartRolePermissionDataRule = (params) => postAction(serviceApi.auth + '/departs/roles/permissions/data-rules', params);
